package com.ztjc.day01_inputevent;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

/**
 * Android中点击事件的写法
 * 思路：
 * 1.编写界面
 * 2.Android中点击事件共有四种写法
 */
public class MainActivity extends Activity implements View.OnClickListener {

    // 声明控件
    private Button button, button2, button3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 实例化控件
        button = (Button) findViewById(R.id.button);
        button2 = (Button) findViewById(R.id.button2);
        button3 = (Button) findViewById(R.id.button3);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "第一种点击事件的写法", Toast.LENGTH_SHORT).show();
            }
        });
        button2.setOnClickListener(new MyOnClickListener());
        button3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Toast.makeText(this, "第三种点击事件的写法", Toast.LENGTH_SHORT).show();
    }

    public void click(View view) {
        Toast.makeText(this, "第四种点击事件的写法", Toast.LENGTH_SHORT).show();
    }

    class MyOnClickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "第二种点击事件的写法", Toast.LENGTH_SHORT).show();
        }
    }
}
